package com.kaili.basic.controller;

import com.kaili.basic.pojo.dto.MdmDevicdCommandQueryDto;
import com.kaili.basic.pojo.dto.MdmDeviceCommandAddDto;
import com.kaili.basic.pojo.dto.MdmDeviceCommandDto;
import com.kaili.basic.pojo.vo.MdmDeviceCommandVo;
import com.kaili.basic.service.IMdmDeviceCommandService;
import com.kaili.basic.version.ApiVersion;
import com.kaili.common.aop.OperateLogAspect;
import com.kaili.common.aop.log.enums.FunctionName;
import com.kaili.common.aop.log.enums.OperateType;
import com.kaili.common.response.RestStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Desc: 设备请求controller
 * @author: shenliqiang
 * @Time: 2019/7/26 9:10
 * @Copyright: © 2018 杭州凯立通信有限公司 版权所有
 * @Warning: 本内容仅限于公司内部传阅, 禁止外泄或用于其它商业目的
 */
@RestController
@ApiVersion(1)
@RequestMapping("/{api_version}")
@Api(tags = "设备命令", description = "设备目录管理")
public class MdmDeviceCommandController {

    private IMdmDeviceCommandService IMdmDeviceCommandService;

    @Autowired
    public MdmDeviceCommandController(IMdmDeviceCommandService IMdmDeviceCommandService) {
        this.IMdmDeviceCommandService = IMdmDeviceCommandService;
    }

    /**
    * @Desc:  新增--暂无使用，设备首次注册是调用mapper中的add方法
    * @author: shenliqiang
    * @Time: 2019/7/26 13:35
    * @param mdmDeviceCommandAddDto
    * @return com.kaili.common.response.RestStatus
    */

    @PostMapping(value = "/devicecommand/addDeviceCommand")
    @ApiOperation(value = "新增在线设备信息",notes = "新增在线设备，需传入deviceId，其余参数新建时可不传",httpMethod = "POST")
    @OperateLogAspect(functionName = FunctionName.deviceCommand,operateType = OperateType.ADD,key = "deviceId")
    public RestStatus addDeviceCommand(@RequestBody MdmDeviceCommandAddDto mdmDeviceCommandAddDto){
        return  this.IMdmDeviceCommandService.addMdmDeviceCommand(mdmDeviceCommandAddDto);
    }

    /**
    * @Desc:  下达设备命令--web接口
    * @author: shenliqiang
    * @Time: 2019/7/26 13:37updateDeviceCommand
    * @param mdmDeviceCommandDtos
    * @return com.kaili.common.response.RestStatus
    */

    @PutMapping(value = "/devicecommand/updateDeviceCommand")
    @ApiOperation(value = "更新设备执行状态-web接口",notes = "更新设备执行状态，后台调用需传入imei或者sn，其余参数1代表执行命令，如后台欲执行命令A，A的value设置为1；pad完成命令A后将调用接口时，A命令参数为0",httpMethod = "PUT")
    @OperateLogAspect(functionName = FunctionName.deviceCommand,operateType = OperateType.UPDATE,key = "deviceId")
    public RestStatus updateDeviceCommandStatusByWeb(@RequestBody @Validated List<MdmDeviceCommandDto> mdmDeviceCommandDtos){
        return this.IMdmDeviceCommandService.updateMdmDeviceCommandStatus(mdmDeviceCommandDtos);
    }

    /**
     * @Desc:  更新设备命令--设备接口
     * @author: shenliqiang
     * @Time: 2019/7/26 13:37updateDeviceCommand
     * @param mdmDeviceCommandDtos
     * @return com.kaili.common.response.RestStatus
     */
    @PutMapping(value = "/devicecommand/updateDeviceCommandByDevice")
    @ApiOperation(value = "更新设备执行状态-设备接口",notes = "更新设备执行状态，pad接口调用需传入imei或者sn,其余参数传入0代表命令执行成功,1代表未执行成功",httpMethod = "PUT")
    @OperateLogAspect(functionName = FunctionName.deviceCommand,operateType = OperateType.UPDATE,key = "deviceId")
    public RestStatus updateDeviceCommandStatusByDevice(@RequestBody MdmDeviceCommandDto mdmDeviceCommandDtos){
        return this.IMdmDeviceCommandService.updateMdmDeviceCommandStatusByDevice(mdmDeviceCommandDtos);
    }
    /**
     * @Desc:  获取单个设备的所有命令--设备接口
     * @author: shenliqiang
     * @Time: 2019/7/26 13:36
     * @param imei
     * @return com.kaili.basic.pojo.vo.MdmDeviceCommandVo
     */

    @GetMapping(value = "/devicecommand/queryDeviceCommands")
    @ApiOperation(value = "获取指定设备的所有命令",notes = "获取指定设备的所有命令，value为1代表需要执行",httpMethod = "GET")
    public MdmDeviceCommandVo queryDeviceCommand(@ModelAttribute MdmDevicdCommandQueryDto imei){
        return this.IMdmDeviceCommandService.queryMdmDeviceCommand(imei);
    }
}
